////#define _CRT_SECURE_NO_WARNINGS 1
////
////#include<iostream>
////#include<string>
////using namespace std;
//////class CVector
//////{
//////private:
//////    int* data;
//////    int n; 
//////public:
//////    CVector()
//////    {
//////        n = 5;
//////        data = new int[5];
//////        for (int i = 0; i < 5; i++)
//////        {
//////            data[i] = i;
//////        }
//////    }
//////    CVector(int n1, int* a)
//////    {
//////        n = n1;
//////        data = new int[n1 + 1];
//////        for (int i = 0; i < n; i++)
//////        {
//////            data[i] = a[i];
//////        }
//////    }
//////    void print()
//////    {
//////        for (int i = 0; i < n - 1; i++)
//////        {
//////            cout << data[i] << " ";
//////        }
//////        cout << data[n - 1] << endl;
//////    }
//////    ~CVector()
//////    {
//////        delete[] data;
//////    }
//////};
//////int main()
//////{
//////    int n;
//////    cin >> n;
//////    int* a = new int[n];
//////    CVector c;
//////    c.print();
//////    for (int i = 0; i < n; i++)
//////    {
//////        cin >> a[i];
//////    }
//////    CVector c1(n, a);
//////    c1.print();
//////    return 0;
//////}
////
////
//////class CVector
//////{
//////
//////private:
//////    int* data;
//////    int n;
//////public:
//////    friend CVector add(const CVector v1, const CVector v2)
//////    {
//////        CVector v3;
//////        v3.n = v1.n;
//////        v3.data = new int[v3.n];
//////        for (int i = 0; i < v3.n; i++)
//////        {
//////            v3.data[i] = v1.data[i] + v2.data[i];
//////        }
//////        return v3;
//////    }
//////    CVector(){}
//////    CVector(int n1, int* a)
//////    {
//////        n = n1;
//////        data = new int[n1 + 1];
//////        for (int i = 0; i < n; i++)
//////        {
//////            data[i] = a[i];
//////        }
//////    }
//////    void print()
//////    {
//////        for (int i = 0; i < n; i++)
//////        {
//////            cout << data[i];
//////            if (i < n - 1)
//////            {
//////                cout << " ";
//////            }
//////        }
//////        cout << endl;
//////    }
//////
//////};
////
//////
//////
//////int main()
//////{
//////    int t;
//////    int n;
//////    int* a1, * a2;
//////    cin >> t;
//////    while (t--)
//////    {
//////        cin >> n;
//////        a1 = new int[n];
//////        a2 = new int[n];
//////        //c.print();
//////        for (int i = 0; i < n; i++)
//////        {
//////            cin >> a1[i];
//////        }
//////        for (int i = 0; i < n; i++)
//////        {
//////            cin >> a2[i];
//////        }
//////        CVector c1(n, a1);
//////        CVector c2(n, a2);
//////        c1.print();
//////        c2.print();
//////        add(c1, c2).print();
//////    }
//////    return 0;
//////}
////
////
////
////#include<iostream>
////using namespace std;
////class cvector
////{
////private:
////    static int sum;
////    int* data;
////    int n;
////public:
////    friend cvector add(const cvector v1, const cvector v2);
////    cvector() { ; }
////    cvector(int n1, int* a)
////    {
////        n = n1;
////        data = new int[n];
////        for (int i = 0; i < n1; i++)
////        {
////            data[i] = a[i];
////        }
////    }
////    //~cvector() { delete[]data; }
////    void print();
////    void init(int n1, int* a);
////    void init2()
////    {
////        sum = 0;
////    }
////    static int getsum()
////    {
////        return sum;
////    }
////};
////int cvector::sum = 0;
////
////void cvector::init(int n1, int* a)
////{
////    n = n1;
////    data = new int[n];
////    for (int i = 0; i < n1; i++)
////    {
////        data[i] = a[i];
////        sum += data[i];
////    }
////}
////cvector add(const cvector v1, const cvector v2)
////{
////    int sum = v1.n;
////    int num[100];
////    for (int i = 0; i < sum; i++)
////    {
////        num[i] = v1.data[i] + v2.data[i];
////    }
////    cvector c(sum, num);
////    return c;
////}
////void cvector::print()
////{
////    cout << data[0];
////    for (int i = 1; i < n; i++)
////    {
////        cout << ' ' << data[i];
////    }
////    cout << endl;
////}
////
////int main()
////{
////    int t, n, m;
////    cin >> t;
////    while (t--)
////    {
////        cin >> m;
////        cvector* cv = new cvector[m];
////        cv[0].init2();
////        for (int i = 0; i < m; i++)
////        {
////            cin >> n;
////            int* num = new int[n];
////            for (int i = 0; i < n; i++)
////            {
////                cin >> num[i];
////            }
////            cv[i].init(n, num);
////        }
////        for (int i = 0; i < m; i++)
////        {
////            cv[i].print();
////        }
////        cout << cv[m - 1].getsum() << endl;
////    }
////    return 0;
////}
//
//
//#include<iostream>
//#include<string> 
//#include<iomanip>
//using namespace std;
//class cv
//{
//	friend class stu;
//private:
//	int num;
//	float* data;
//public:
//	cv() {};
//	cv(int num1, float* data1) {
//		num = num1;
//		int i = 0;
//		data = new float[num];
//		for (i = 0; i < num; i++)
//		{
//			data[i] = data1[i];
//		}
//	};
//	void set(int num1, float* data1)
//	{
//		num = num1;
//		int i = 0;
//		data = new float[num];
//		for (i = 0; i < num; i++)
//		{
//			data[i] = data1[i];
//		}
//	}
//
//	cv(cv& b)
//	{
//		num = b.num;
//		for (int i = 0; i < b.num; i++)
//		{
//			data[i] = b.data[i];
//		}
//	};
//	friend float ave(cv& a)
//	{
//		float sum = 0;
//		for (int i = 0; i < a.num; i++)
//		{
//			sum += a.data[i];
//		}
//
//		return sum / a.num;
//	};
//};
//
//class stu
//{
//private:
//	string name;
//	cv sco;
//public:
//	stu(string name1, int n1, float* data1)
//	{
//		name = name1;
//		sco.set(n1, data1);
//	}
//
//	void pri()
//	{
//		cout << name << " ";
//		for (int i = 0; i < sco.num; i++)
//		{
//			cout << fixed << setprecision(0) << sco.data[i] << " ";
//		}
//		float ave1 = ave(sco);
//		cout << fixed << setprecision(2) << ave1 << endl;
//	}
//};
//
//int main() 
//{
//	string name;
//	int num;
//	while (cin >> name)
//	{
//		cin >> num;
//		float* data = new float[num];
//
//		for (int i = 0; i < num; i++)
//		{
//			cin >> data[i];
//		}
//		stu stu1(name, num, data);
//		stu1.pri();
//		delete[]data;
//	}
//	return 0;
//}


#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
class CVector
{
private:
    int* data;
    int n;
    static int sum;
public:
    friend class CMatrix;
    CVector()
    {
        n = 5;
        data = new int[5];
        for (int i = 0; i < 5; i++)
        {
            data[i] = i;
        }
    }
    CVector(int n1, int* a)
    {
        n = n1;
        data = new int[n];
        for (int i = 0; i < n; i++)
        {
            data[i] = a[i];
            sum += a[i];
        }
    }
    void print()
    {
        for (int i = 0; i < n - 1; i++)
        {
            cout << data[i] << " ";
        }
        cout << data[n - 1];
    }
    ~CVector()
    {
        delete[] data;
    }
    CVector(CVector& c)
    {
        this->n = c.n;
        data = new int[n];
        for (int i = 0; i < n; i++)
        {
            data[i] = c.data[i];
        }
    }
};
int CVector::sum = 0;

class CMatrix
{
private:
    int n;
    int** data;
public:
    CMatrix() {};
    CMatrix(int n1, int** a)
    {
        int i, j;
        n = n1;
        data = new int* [n];
        for (i = 0; i < n; i++)
        {

            data[i] = new int[n];

        }
        for (i = 0; i < n; i++)
        {
            for (j = 0; j < n; j++)
            {
                data[i][j] = a[i][j];
            }
        }
    }
    ~CMatrix()
    {
        delete[]data;
    }
    CVector multi(const CVector& v1)
    {
        int* w = new int[n];
        for (int i = 0; i < n; i++)
        {
            w[i] = 0;
        }
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
            {
                w[i] += data[i][j] * v1.data[j];
            }
        }
        CVector c(n, w);
        return c;
    }
    bool ifright(const CVector& v1)
    {
        if (n == v1.n)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
};
int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        int n;
        int** data;
        int i, j;
        cin >> n;
        data = new int* [n];
        for (i = 0; i < n; i++)
        {
            data[i] = new int[n];
        }
        for (i = 0; i < n; i++)
        {
            for (j = 0; j < n; j++)
            {
                cin >> data[i][j];
            }
        }
        CMatrix c1(n, data);
        int n2;
        cin >> n2;
        int* a = new int[n2];
        for (int i = 0; i < n2; i++)
        {
            cin >> a[i];
        }
        CVector v1(n2, a);
        if (c1.ifright(v1))
        {
            c1.multi(v1).print();
        }
        else
        {
            cout << "error" << endl;
        }
    }
    return 0;
}